<%--
  Created by IntelliJ IDEA.
  User: 朱泽丹
  Date: 2021-12-09
  Time: 10:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>ajax后台交互获取集合数据内容</title>
    <script src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
    <script>
        $(function (){
            // $("#btn").click()
            $("#btn").click(function (){
                $.post({
                    url:"${pageContext.request.contextPath}/a2.action",
                    success:function (data){
                        console.log(data);
                        var html="";
                        for (var i=0;i<data.length;i++){
                            html+="<tr>"+
                            "<td>"+data[i].name+"</td>"+
                            "<td>"+data[i].age+"</td>"+
                            "<td>"+data[i].sex+"</td>"+
                            "</tr>"
                        }
                        $("#context").html(html);
                    }
                })
            })
        })
    </script>
</head>
<body>
<input type="button" id="btn" value="获取集合数据">
<table width="60%" align="center" border="2">
    <tr>
        <td>name</td>
        <td>sex</td>
        <td>age</td>
    </tr>
    <tbody id="context">

    </tbody>
</table>
</body>
</html>
